package codepulse.blogmoon.cn.system.controller.admin;

import codepulse.blogmoon.cn.common.context.Context;
import codepulse.blogmoon.cn.common.entity.Result;
import codepulse.blogmoon.cn.common.utils.BaseConvert;
import codepulse.blogmoon.cn.system.dto.admin.SysAdminMenuTreeDTO;
import codepulse.blogmoon.cn.system.service.SysAdminMenuService;
import codepulse.blogmoon.cn.system.service.SysAdminRoleService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.List;

@RestController
@RequestMapping("/admin/menu")
public class AdminMenuController {

    @Resource
    private SysAdminMenuService sysAdminMenuService;


    @GetMapping("/routes")
    public Result<List<SysAdminMenuTreeDTO>> menuTree() {
        return Result.success(sysAdminMenuService.getTree(Context.get().getBizAcctId()));
    }


    @GetMapping("/all-menu")
    public Result<List<SysAdminMenuTreeDTO>> allMenu() {
        return Result.success(sysAdminMenuService.allMenu());
    }

    @GetMapping("/detail/{id}")
    public Result<SysAdminMenuTreeDTO> detail(@PathVariable("id") Long id) {
        return Result.success(BaseConvert.convert(sysAdminMenuService.getById(id), SysAdminMenuTreeDTO.class));
    }

    @PostMapping("/save")
    public Result save(@RequestBody SysAdminMenuTreeDTO dto) {
        sysAdminMenuService.insertOrUpdate(dto);
        return Result.success();

    }

    @DeleteMapping("/{id}")
    public Result remove(@PathVariable("id") Long id) {
        sysAdminMenuService.removeMenu(id);
        return Result.success();
    }





}

